<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .div1 {
      width: 100px;
      height: 100px;
      background-color: blue;
    }
    .div2 {
      width: 150px;
      height: 150px;
      background-color: yellow;
    }
    .div3 {
      width: 200px;
      height: 200px;
      background-color: red;
    }
    .div4 {
      width: 200px;
      height: 200px;
      border: 1px solid red;
    }
    .p1 {
      background-color: aquamarine;
    }
  </style>
</head>
<body>
  <div id="app">
    <h1>vue的修饰符：减少代码量，实现小的功能</h1>
    <p>表单修饰符1：.number:只能输入数字。用于金额和数量</p>
    <input type="text" v-model.number="val1">
    <p>{{val1}}</p>
    <hr>
    <p>表单修饰符2：.trim去掉首尾空格。用于输入昵称</p>
    <input type="text" v-model.trim="val2">
    <p>{{val2}}</p>
    <hr>
    <p>表单修饰符3：.lazy减少对用户的响应，延迟响应。将v-model的input事件改为change事件</p>
    <input type="text" v-model.lazy="val3">
    <p>{{val3}}</p>
    <p>事件修饰符:prevent阻止默认事件</p>
    <div class="div1" @contextmenu.prevent="showMenu"></div>
    <p>事件修饰符：stop阻止冒泡</p>
    <div class="div3" @click="click3">
      <div class="div2" @click="click2">
        <div class="div1" @click.stop="click1"></div>
      </div>
    </div>
    <p>事件修饰符：capture，在冒泡的过程中优先执行。</p>
    <div class="div3" @click.capture="click3">
      <div class="div2" @click="click2">
        <div class="div1" @click="click1"></div>
      </div>
    </div>
    <p>事件修饰符:once,事件只执行一次</p>
    <button @click.once="showHello">click</button>
    <p>事件修饰符:self,只执行自己的事件，不包含子元素的事件。参考事件委托</p>
    <div class="div4" @click.self="divFn">
      我是div的内容
      <p class="p1" @click="pFn">我是p的内容</p>
    </div>
    <hr>
    <p>键盘修饰符:回车键以及26个字母都已经被注册了，按下对应的键才执行相应的函数</p>
    <p>键盘修饰符的串联:以功能键和字母键为例，同时按下ctrl和f：@keyup.ctrl.f</p>
    <input type="text" @keyup.enter="showKey">
    <hr>
    <p>鼠标修饰符</p>
    <button @click.left="clickLeft">左击</button>
    <button @click.middle="clickMid">通过滚轮点击</button>
    <button @click.right="clickRight">右键</button>
  </div>
  <script src="./vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        val1: '',
        val2: '', 
        val3: '', 
      },
      methods: {
        showMenu() {
          console.log(666);
        },
        click3() {
          console.log('我是div3，我被点击了！');
        },
        click2() {
          console.log('我是div2，我被点击了！');
        },
        click1() {
          console.log('我是div1，我被点击了！');
        },
        showHello() {
          console.log('hello');
        },
        divFn() {
          console.log('div被点击了');
        },
        pFn() {
          console.log('p被点击了');
        },
        showKey() {
          alert('登陆成功！')
        },
        clickLeft() {
          console.log('left');
        },
        clickMid() {
          console.log('mid');
        },
        clickRight() {
          console.log('right');
        }
      },
    })
  </script>
</body>
</html>